package cn.lycode.framework.web.controller;

import cn.lycode.common.constant.ParamConstants;
import cn.lycode.common.core.controller.BaseController;
import cn.lycode.common.core.domain.AjaxResult;
import cn.lycode.common.core.domain.model.user.RegisterBody;
import cn.lycode.common.utils.StringUtils;
import cn.lycode.framework.web.service.SysRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 注册验证
 */
@RestController
public class SysRegisterController extends BaseController {
    @Autowired
    private SysRegisterService registerService;

    @PostMapping("/register")
    public AjaxResult<Object> register(@RequestBody RegisterBody user) {
//        configService.selectConfigByKey("sys.account.registerUser");
        if (!("true".equals(ParamConstants.registerEnabled))) {
            return AjaxResult.failed("当前系统没有开启注册功能！");
        }
        String msg = registerService.register(user);
        return StringUtils.isEmpty(msg) ? AjaxResult.success() : AjaxResult.failed(msg);
    }
}